
package com.operatehistorymodule.servlet;
import com.operatehistorymodule.bean.TbOperateHistory;
import com.operatehistorymodule.dao.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import util.*;

public class TbOperateHistoryServlet extends HttpServlet{
    public void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String method = request.getParameter("method")==null?"":request.getParameter("method");
        if("add".equals(method)){
        String moduleName=request.getParameter("moduleName");
        int userId=Integer.parseInt(request.getParameter("userId"));
        String userName=request.getParameter("userName");
        int userAction=Integer.parseInt(request.getParameter("userAction"));
        String userActionName=request.getParameter("userActionName");
        String createTime=request.getParameter("createTime");

            if(new TbOperateHistoryDAO().add(new TbOperateHistory(moduleName,userId,userName,userAction,userActionName,createTime))){
            request.getSession().setAttribute("result", "添加成功");
            }else{            
            request.getSession().setAttribute("result", "添加失败");
            }
             request.getSession(true).setAttribute("tbOperateHistoryList",new TbOperateHistoryDAO().getTbOperateHistoryAll());
            response.sendRedirect("OperatehistoryModule/TbOperateHistoryList.jsp");
        }
        if("del".equals(method)){
            if(UtilDAO.delin("Tb_OperateHistory", "OperateHistoryId", request.getParameter("delIds"))){            
            request.getSession().setAttribute("result", "删除成功");
            }else{            
            request.getSession().setAttribute("result", "删除失败");
            }
             request.getSession(true).setAttribute("tbOperateHistoryList",new TbOperateHistoryDAO().getTbOperateHistoryAll());
            response.sendRedirect("OperatehistoryModule/TbOperateHistoryList.jsp");
        }
        if("edit".equals(method)){
        int operateHistoryId=Integer.parseInt(request.getParameter("operateHistoryId"));
        String moduleName=request.getParameter("moduleName");
        int userId=Integer.parseInt(request.getParameter("userId"));
        String userName=request.getParameter("userName");
        int userAction=Integer.parseInt(request.getParameter("userAction"));
        String userActionName=request.getParameter("userActionName");
        String createTime=request.getParameter("createTime");

            if(new TbOperateHistoryDAO().edit(new TbOperateHistory(operateHistoryId,moduleName,userId,userName,userAction,userActionName,createTime))){
            request.getSession().setAttribute("result", "修改成功");
            }else{            
            request.getSession().setAttribute("result", "修改失败");
            }
             request.getSession(true).setAttribute("tbOperateHistoryList",new TbOperateHistoryDAO().getTbOperateHistoryAll());
            response.sendRedirect("OperatehistoryModule/TbOperateHistoryList.jsp");
        }
        if ("list".equals(method)) {
             request.getSession(true).setAttribute("tbOperateHistoryList",new TbOperateHistoryDAO().getTbOperateHistoryAll());
            response.sendRedirect("OperatehistoryModule/TbOperateHistoryList.jsp");
        	}
        if ("listById".equals(method)) {
             request.getSession(true).setAttribute("tbOperateHistory",new TbOperateHistoryDAO().getTbOperateHistoryByOperateHistoryId(Integer.parseInt(request.getParameter("operateHistoryId"))));
            response.sendRedirect("OperatehistoryModule/TbOperateHistoryOperate.jsp");
    	}
        if("showadd".equals(method)){
            
            request.getSession(true).removeAttribute("tbOperateHistory");
            response.sendRedirect("OperatehistoryModule/TbOperateHistoryOperate.jsp");
        }
    }
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doGet
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.processRequest(request, response);
    }// end method doPost
}
